package cn.bugstack.springframework.beans.factory.support;

import cn.bugstack.springframework.beans.BeanException2;
import cn.bugstack.springframework.beans.BeansException;
import cn.bugstack.springframework.beans.factory.BeanFactory;
import cn.bugstack.springframework.beans.factory.BeanFactory2;
import cn.bugstack.springframework.beans.factory.config.BeanDefinition2;

public abstract class AbstractBeanFactory2 extends DefaultSingletonBeanRegistry2 implements BeanFactory2 {

    @Override
    public Object getBean(String name) throws BeansException {
        Object bean = getSingleton(name);
        if (bean!=null){
            return bean;
        }
        BeanDefinition2 beanDefinition2 = getBeanDefinition(name);
        return createBean(name,beanDefinition2);
    }

    protected abstract BeanDefinition2 getBeanDefinition(String name) throws BeanException2;

    protected abstract Object createBean(String name, BeanDefinition2 beanDefinition2) throws BeanException2;


}
